package com.pj.lib.auraServer.components.DB.tables;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Map;

import com.pj.lib.auraServer.components.DB.DB;
import com.pj.lib.auraServer.components.DB.tables.PG.PGUser;
import com.pj.lib.auraServer.exceptions.AuraServerException;
import com.pj.lib.auraServer.utils.Log;

public interface TableInterface {

	/**
	 * This functions creates table - please don't use it
	 * @throws AuraServerException
	 * @throws SQLException
	 */
	public void create() throws AuraServerException, SQLException;
	/**
	 * This function is executed after creating all tables - it is use to add some constraints
	 * @throws AuraServerException
	 * @throws SQLException
	 */
	public void afterCreate() throws AuraServerException, SQLException;
	/**
	 * This function deleting table - please don't use it
	 * @throws AuraServerException
	 * @throws SQLException
	 */
	public void delete() throws AuraServerException, SQLException;
	/**
	 * Function which returns sql table name
	 * @return sql table name
	 */
	public String getTableName();
	public void setTableName(String name);
	/**
	 * Returns name of table sequence (NOT next sequence number)
	 * @return name of table sequence
	 */
	public String getTableSequence();
	public void setTableSequence(String name);
	/**
	 * It is executed on start of system - not need to use it when system is running
	 * @param dbTables
	 * @throws AuraServerException
	 * @throws SQLException
	 */
	public void createIfNotExists(ArrayList<Map<String, Object>> dbTables)  throws AuraServerException, SQLException;
	/**
	 * It is executed on start of system - not need to use it when system is running
	 * @param db
	 */
	public void setDB(DB db);
	/**
	 * Function returns default order of table
	 * @return default order of table
	 */
	public String getDefaultOrder();
	
	/**
	 * Function is used to add new rows to table
	 * @param obj Map of column names (as key) and column values (as value) which you want to add
	 * @return Id of entered row (if it has id)
	 * @throws AuraServerException
	 * @throws SQLException
	 */
	public Long add(Map<String, Object> obj) throws AuraServerException, SQLException;
	/**
	 * Function for updating row.
	 * @param obj Map of column names (as key) and column values (as value) which you want to update
	 * @param selection String after "WHERE" closure. There can be "?" as values - than add values to selectionArgs
	 * @param selectionArgs Array of values if you use "?" symbols in selection string
	 * @throws AuraServerException
	 * @throws SQLException
	 */
	public void update(Map<String, Object> obj, String selection, Object[] selectionArgs) throws AuraServerException, SQLException;
	/**
	 * Function for deleting row.
	 * @param selection String after "WHERE" closure. There can be "?" as values - than add values to selectionArgs
	 * @param selectionArgs Array of values if you use "?" symbols in selection string
	 * @throws AuraServerException
	 * @throws SQLException
	 */
	public void delete(String selection, Object[] selectionArgs) throws AuraServerException, SQLException;
	/**
	 * Function for quering sql tables.
	 * @param projection Columns whose you want to return. If null it means "*" in sql.
	 * @param selection String after "WHERE" closure. There can be "?" as values - than add values to selectionArgs
	 * @param selectionArgs Array of values if you use "?" symbols in selection string
	 * @param sortOrder Sort order of query. If it is null it will get default sort order for table.
	 * @return List of maps with keys as columns names and values as column value.
	 * @throws AuraServerException
	 * @throws SQLException
	 */
	public ArrayList<Map<String, Object>> get(String[] projection, String selection, Object[] selectionArgs, String sortOrder) throws AuraServerException, SQLException;
	
}
